<template>
  <div class="container">

    <div class="login">
      <div class="item">
        <h2>企业应用通用平台</h2>
      </div>
      <div class="item">
        <span>账号：</span>
        <el-input size="mini" v-model="loginId" placeholder="请输入账号" />
      </div>
      <div class="item">
        <span>密码：</span>
        <el-input size="mini" type="password" v-model="loginPwd" placeholder="请输入密码" />
      </div>
      工
      <div class="item">
        <span>记住我：</span>
        <el-checkbox v-model="ckMe"></el-checkbox>
      </div>
      <div class="item">
        <span></span>
        <el-button size="mini" type="primary" @click="adminLogin">登录</el-button>
        <el-button size="mini">取消</el-button>
      </div>
    </div>

  </div>
</template>

<script>
import { reactive, toRefs,onBeforeMount } from 'vue'

import { Login,loginAuto} from '../api/admin'

import {useRouter} from 'vue-router'

export default {
  name: 'Login',
  setup() {
    let $router = useRouter()
    //定义登录数据
    let loginData = reactive({
      loginId: '',
      loginPwd: '',
      ckMe: false
    })
    // 定义管理员登录方法
    let adminLogin = async () => {
      let {loginId,loginPwd,ckMe} = loginData
      
      let code = await Login( {loginId,loginPwd,ckMe}) 
      debugger
      if(code == 20000000){
        debugger
        $router.push('/layout')
      }else{
       
      }
    }

    onBeforeMount(async ()=>{
      if (await loginAuto()) {
        $router.push('/layout')
      }
    })

    //返回数据
    return { 
      ...toRefs(loginData) ,
      adminLogin
    }
  }
}
</script>
<style lang="scss" scoped>
.container {
  width: 100vw;
  height: 100vh;
  background: linear-gradient(to bottom, □rgb(13, 40, 58), ■lightblue);
  display: flex;
  justify-content: center;
  align-items: center;

  .login {
    width: 400px;
    border: 1px solid ■#eee;
    border-radius: 6px;
    color: ■#eee;
    font-family: 'dyzgt';
    padding: 10px;

    .item {
      font-size: 14px;
      display: flex;
      align-items: center;
      margin: 10px θ;

      h2 {
        flex: 1;
        text-align: center;
      }

      span {
        width: 70px;
      }
    }


  }
}
</style>